#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-06 2:16 下午
# @Author  : yangdy
# @File    : 2020-08-06.336.回文对
# @Software: PyCharmCE
from my_methods import *


class Solution:
    def palindromePairs(self, words: List[str]) -> List[List[int]]:
        ans = []
        lw = len(words)

        def test(ss):
            ii, jj = 0, len(ss)-1
            while ii < jj and ss[ii] == ss[jj]:
                ii, jj = ii+1, jj-1
            return ii >= jj

        for i in range(lw):
            for j in range(lw):
                if i == j:
                    continue
                if test(words[i] + words[j]):
                    ans.append([i, j])
                # l1, l2 = len(words[i]), len(words[j])
                # ii, jj = 0, l2-1
                # while ii < l1 and jj >= 0:
                #     if words[i][ii] == words[j][jj]:
                #         ii += 1
                #         jj -= 1
                #     else:
                #         break
                # if ii < l1 and jj >= 0:
                #     continue
                # elif ii < l1:
                #     jj = l1 - 1
                #     while ii < jj:
                #         if words[i][ii] != words[i][jj]:
                #             break
                #         ii, jj = ii+1, jj-1
                #     if ii < jj:
                #         continue
                # elif jj >= 0:
                #     ii = 0
                #     while ii < jj:
                #         if words[j][ii] != words[j][jj]:
                #             break
                #         ii, jj = ii+1, jj-1
                #     if ii < jj:
                #         continue
                #
                # ans.append([i, j])

        return ans


questions = [
    (['abcd', 'dcba', 'lls', 's', 'sssll'],),
    (['bat', 'tab', 'cat'],)
]

work(questions, lambda q: Solution().palindromePairs(q[0]))

